/**
 * 功能描述：
 */
define(function (require, exports, module) {
    //引入视图基类
    var ELView = require("elview");

    //assets
    var template = require("./assets/tpl/prodDefine_main.tpl");
    require("./assets/css/prodDefine_main.css");

    //component
    var cSubnav = require("./component/prodDefineGrid");
    var cForm = require("./component/prodDefineForm");
    var cSubGrid = require("./component/prodDefineSubnav");
    var cGrid = require("./component/prodDefineSubGrid");
    var cSubForm = require("./component/prodDefineSubForm");
    //store
    var cStore = require("./store/prodDefineStore");
    //service
    var cSvc = require("./service/prodDefineSvc");
    //handler
    var cHandler = require("./handler/prodDefineHandler");

    var App = ELView.extend({
        attrs: {
            template: template,
            delPks: []
        },
        store: cStore,
        service: cSvc,
        handler: cHandler,
        initComponent: function (params, widget) {
            //初始化组件
            cSubnav.initComponent(widget);
            cGrid.initComponent(widget);
            cForm.initComponent(widget);
            cSubGrid.initComponent(widget);
            cSubForm.initComponent(widget);
        },
        afterInitComponent: function(params,widget){
        	widget.service.qryRules({},function(data){
        		var ret = widget.store.groupRulesOrScopes(data);
        		var subForm = widget.get("subForm");
        		subForm.setData("settlementsRules_Expense",ret.expense);
        		subForm.setData("settlementsRules_BedSubsidy",ret.bedSubsidy);
        		subForm.setData("settlementsRules_Coupon",ret.coupon);
        	});
        	this.service.qryScopes({},function(data){
        		var ret = widget.store.groupRulesOrScopes(data);
        		var subForm = widget.get("subForm");
        		subForm.setData("ruleScope_Expense",ret.expense);
        		subForm.setData("ruleScope_BedSubsidy",ret.bedSubsidy);
        		subForm.setData("ruleScope_Coupon",ret.coupon);
        	});
        },
        toList: function(){
            this.hide([".J-form",".J-subGrid",".J-subForm"]).show([".J-grid"]);
            this.get("subnav").hide(["return","save"]).show(["add","search"]);
        },
        toCard: function(){
            this.show([".J-form",".J-subGrid"]).hide([".J-grid",".J-subForm"]);
            this.get("subnav").show(["return","save"]).hide(["add","search"]);
        },
        toSubForm: function(){
        	this.show([".J-subForm"]).hide([".J-form",".J-grid",".J-subGrid"]);
            this.get("subnav").hide(["add","search","return","save"]);
        }
    });

    module.exports = App;
});